'use strict';

module.exports = (app) => {
  class MoveService extends app.Service {
    async move() {
      const { app, ctx } = this;
      const { Admin, Project } = app.model.Tables.Com;
      const staff = await ctx.curl('http://localhost:7002/api/getStudent');
      const data = JSON.parse(staff.data).data;
      console.log(data);

      for (let i = 1; i < data.length; i++) {
        //创建管理员
        let password = await ctx.genHash('123456');
        console.log(data[i].phone, data[i].name);
        let registerRes = await Admin.create({
          phone: data[i].phone,
          name: data[i].name,
          password: password,
          grade: 42,
        });
        //创建用户对应的项目
        await Project.create({
          adminId: registerRes.dataValues.id,
          adminName: data[i].name,
          adminPhone: data[i].phone,
          adminAvatar: registerRes.dataValues.avatar,
        });
      }
      return data;
    }
  }
  return MoveService;
};
